<?php
/**
 * 缓存模型...
 * @author zengjie
 *
 */
class Cache_model extends CI_Model {
	
	private $life_time = 84600;
	
	public function __construct() {
		parent::__construct ();
		$this->load->driver ( 'cache', array (
				'adapter' => 'redis' 
		) );
		
		$this->select(15);
	}
	
	public function set_info($cache_key, $cache_data, $ttl = 84600) {
		$cache_val = json_encode ( $cache_data );
		return $this->cache->save ( $cache_key, $cache_val, $ttl );
	}
	
	public function get_info($cache_key) {
		if (false == ($rs = $this->cache->get ( $cache_key ))) {
			return false;
		}
		
		return json_decode ( $rs, true );
	}
	
	function queue_lpop($queue) {
		$rs = $this->cache->lpop ( $queue );
		return json_decode ( $rs, true );
	}
	
	function queue_rpush($queue, $data) {
		$value = json_encode ( $data );
		$rs = $this->cache->rpush ( $queue, $value );
		
		return $rs;
	}
	
	function queue_llen($queue) {
		$rs = $this->cache->llen ( $queue );
		
		return $rs;
	}
	
	function select($db) {
		$rs = $this->cache->select ( $db );
	
		return $rs;
	}

	function zcard($cache_key) {
		$rs = $this->cache->zcard ( $cache_key );
	
		return $rs;
	}
}
?>